﻿using Gfw.Infrastructure.Account;
using Gfw.Infrastructure.ExceptionImpl;
using Gfw.Models.Account;
using Gfw.Repositories.Account;
using Gfw.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Gfw.Infrastructure.Facilities
{
    /// <summary>
    /// 会员资料修改手续费100元入库
    /// </summary>
    public class UserInfoCommissionFacility : IFacility
    {
        #region Private Fields

        protected string _userID;
        protected string _userName;

        #endregion

        #region 构造函数初始化

        public UserInfoCommissionFacility(string userID, string userName)
        {
            this._userID = userID;
            this._userName = userName;
        }

        #endregion

        #region IFacility 成员

        /// <summary>
        /// 手续费100入库操作
        /// </summary>
        /// <param name="unitOfWork"></param>
        public virtual void Execute(Repository.UnitOfWork unitOfWork = null)
        {
            try
            {
                UnitOfWork work = unitOfWork ?? new UnitOfWork();
                ActCompanyBargainRepository bargainRep = new ActCompanyBargainRepository(); // 修改：公司帐户交易明细

                ActCompanyBargain bargainCommission = new ActCompanyBargain() // 手续费
                {
                    Id = Guid.NewGuid().ToString(),
                    Userid = this._userID,
                    TradeType = (int)CompanyTradeTypeEnum.ChangeInformation,
                    Income = 100,
                    Outlay = 0,
                    Balance = 0,
                    TradeDate = DateTime.Now,
                    TradeAbstract = this._userName + " 修改资料手续费",
                    AwardSerialNo = "",
                    TaxationSerialNo = "",
                };

                bargainRep.Save(bargainCommission, work);

                if (unitOfWork == null)
                    work.Commit();
            }
            catch (System.Exception ex)
            {
                throw new GfwVerifyException(ex.Message);
            }
        }

        #endregion
    }
}
